<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('交易未清算的数据')" />
</head>
<body class="gray-bg">
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>
							<li>
								<label style="width: 100px;">商户编号：</label>
								<input type="text" name="merno"/>
							</li>
							<li>
								<label style="width: 100px;">上游商户编号：</label>
								<input type="text" name="ld_merno"/>
							</li>
							<li>
								<label style="width: 100px">交易流水号：</label>
								<input type="text" name="balances_serial"/>
							</li>

							<li>
								<label  style="width: 100px">结算人姓名：</label>
								<input type="text" name="screen_name"/>
							</li>
							<li>
								<label  style="width: 100px">交易类型：</label>
								<select name="type" id="type">
									<option value="1">线下交易</option>
									<option value="2">线上交易</option>
								</select>
							</li>
							<li>
								<label style="width: 100px">原交易流水号：</label>
								<input type="text" name="ori_sys"/>
							</li>
							<li class="select-time">
								<label style="width: 100px">日期：</label>
								<input type="text" class="time-input" id="startTime" placeholder="开始时间" name="mindDate"/>
								<span>-</span>
								<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="maxDate"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="saveQingsuan()" shiro:hasPermission="qs:acc:noCk">
					<i class="fa fa-edit"></i> 清算未出款
				</a>
				<a class="btn btn-success single disabled" onclick="bl()" shiro:hasPermission="qs:acc:bl">
					<i class="fa fa-edit"></i> 出款补录
				</a>
				<a class="btn btn-success single disabled" onclick="jd()" shiro:hasPermission="qs:acc:jd">
					<i class="fa fa-edit"></i> 出款解冻
				</a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table"  class="table text-nowrap"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var prefix = ctx + "settleInfo/settleInfo";

		$(function()  {
            var options = {
                url: prefix + "/jqDate",
		        showSearch: false,
		        showRefresh: false,
		        showToggle: false,
		        showColumns: false,
	            clickToSelect:true,
                columns: [
					{
						checkbox: true
					},
				{
					field : 'SERIAL',
					title : '交易流水号'
				},
				{
					field : 'MERNO',
					title : '商户编号'
				},
				{
					field : 'LD_MERNO',
					title : '上游商户编号'
				},
				{
					field : 'MER_NAME',
					title : '商户名称'
				},
				{
					field : 'MER_CATEGORY',
					title : '商户类别',
					formatter: function(value, row, index) {
						if ("0"==value){
							return '<span style="color:blue;">标准类</span>';
						}else if("1"==value){
							return '<span style="color:green;">优惠类</span>';
						}else if("2"==value){
							return '<span style="color:green;">减免类</span>';
						}else{
							return "未知";
						}
					}
				},
				{
					field : 'BANK_NAME',
					title : '开户行名称'
				},
				{
					field : 'BANK_NAME',
					title : '结算人'
				},
				{
				    field : 'SHOWSCREENNUM',
				    title : '结算卡'
				},
				{
					field : 'LOCALDATE',
					title : '交易时间',
					formatter: function(value, row, index) {
						return row.LOCALDATE+' '+row.LOCALTIME;
					}
				},
				{
					field : 'PAN',
					title : '交易卡号'
				},
				{
					field : 'AMOUNT',
					title : '交易金额',
					formatter: function(value, row, index) {
						return $.table.rmbFormatter(value);
					}
				},
				{
					field : 'STATUS',
					title : '交易状态',
					formatter: function(value, row, index) {
						if ("0"==value){
							return '<span style="color: green;"> 交易成功</span>';
						}else if("1"==value){
							return ' <span style="color: blue;">补录</span>';
						}else if("00"==value){
							return ' <span style="color: blue;">线上交易成功</span>';
						}else if("01"==value){
							return ' <span style="color: blue;">线上交易补录</span>';
						}else{
							return "未知";
						}
					}
				},
					{
						field: 'MSG_TYPE',
						title: '交易类型',
						formatter:function(value,row,index){
							if (value == '1761'){
								return "WAP最优惠消费";
							} else if (value == '1801'){
								return "WAP好优选消费";
							} else if (value == '1821'){
								return "WAP全积分消费";
							} else if (value == '1411'){
								return "银联二维码被扫";
							} else if (value == '1611'){
								return "银联二维码主扫";
							} else if (value == '3091'){
								return "预授权完成撤销";
							} else if (value == '1091'){
								return "预授权完成";
							} else if (value == '1621'){
								return "支付宝主扫";
							} else if (value == '1861'){
								return "银联在线";
							} else if (value == '1211'){
								return "主动提现";
							} else if (value == '1221'){
								return "自动提现";
							} else if (value == '1311'){
								return "满额提现";
							} else if (value == '1431'){
								return "微信被扫";
							} else if (value == '1941'){
								return "云闪付";
							} else if (value == '1841'){
								return "手机pay";
							} else if (value == '1101'){
								return "消费";
							} else if (value == '5151'){
								return "退货";
							} else if (value == '1421'){
								return "支付宝被扫";
							} else if (value == '1631'){
								return "微信主扫";
							} else {
								return "未知";
							}
						}
					},
					{
						field : 'QMW_AMOUNT',
						title : '提现金额'
					},
					{
						field : 'TRAD_STATUS',
						title : '应答码',
						formatter: function(value, row, index) {
							if ("00" == value){
								return '<span style="color: green;"> 成功</span>';
							}else{
								return value;
							}
						}
					},
					{
						field : 'ORI_SYS',
						title : '原流水号'
					}
				]
            };
            $.table.init(options);
        });

		/**
		 * 交易未清算
		 */
		function saveQingsuan() {
			$.modal.confirm("确认发起清算吗?", function() {
				var arrays = $.table.selectColumns("SERIAL");
				if ($.common.isEmpty(arrays)){
					$.modal.msgError("请至少选择一条记录");
					return;
				}

				var type = $('#type').val();
				//1 线下 2 线上
				//0 线下 1 线上
				type = type == '1' ? "0" : "1";
				var data = {"serials":arrays.toString(),"type":type};
				if (type == '0'){
					$.operate.submit(prefix + "/saveQingsuan", "post", "json",data);
				} else if (type == '1'){
					$.operate.submit(prefix + "/saveQingsuanOnline", "post", "json",data);
				} else {
					$.modal.msgError("线上或线下状态错误");
					return;
				}
			});
		}

		/**
		 * 补录
		 * */
		function bl() {
			var merNo = $.table.selectColumns("MERNO")[0];
			var stan = $.table.selectColumns("STAN")[0];
			if ($.common.isEmpty(merNo)) {
				$.modal.alertWarning("请至少选择一条记录");
				return;
			}
			$.modal.confirm("确定要补录吗?", function() {
				$.post(prefix + "/saveBuLu",{'mer_no':merNo,'stan':stan,'type':$('#type').val()},function(result){
					if (result.code == '0'){
						$.table.refresh();
						return;
					} else {
						$.modal.msgError(result.msg);
						return;
					}
				});
			})
		}
		/**
		 * 商户解冻/冻结
		 * */
		function jd() {
			var merNo = $.table.selectColumns("MERNO")[0];
			var stan = $.table.selectColumns("STAN")[0];
			if ($.common.isEmpty(merNo)) {
				$.modal.alertWarning("请至少选择一条记录");
				return;
			}
			$.modal.confirm("确定要解冻吗?", function() {
				$.post(prefix + "/saveJieDong",{'mer_no':merNo,'stan':stan,'type':$('#type').val()},function(result){
					if (result.code == '0'){
						$.table.refresh();
						return;
					} else {
						$.modal.msgError(result.msg);
						return;
					}
				});
			})
		}


    </script>
</body>
</html>